/**
 * Copyright 2018 orivil.com. All rights reserved.
 * Use of this source code is governed by a MIT-style
 * license that can be found at https://mit-license.org.
 */

package access

import "net/rpc"

type Client struct {
	client *rpc.Client
}

func (c *Client) GetTicket(appid, secret string) (ticket string, err error) {
	err = c.client.Call("Access.GetTicket", &Config{AppID: appid, Secret:secret}, &ticket)
	return
}

func (c *Client) GetToken(appid, secret string) (token string, err error) {
	err = c.client.Call("Access.GetToken", &Config{AppID: appid, Secret:secret}, &token)
	return
}

// 新建 rpc 客户端
func NewClient(address string) (c *Client, e error) {
	client, err := rpc.DialHTTP("tcp", address)
	if err != nil {
		return nil, err
	} else {
		return &Client{client:client}, nil
	}
}